<template>
  <div>
    <div style="float: left;"><p class="title"><i class="el-icon-tickets"></i>班级信息</p>
    </div>
    <div style="float: right;margin-bottom: 5px">
      <el-button type="primary" @click="createStoreHouse">创建资源库</el-button>
    </div>
    <el-table border :data="tableData" style="width: 100%">
      <el-table-column
        type="index">
      </el-table-column>
      <el-table-column
        sortable
        prop="id"
        label="资源库编号"
        align="center">
      </el-table-column>
      <el-table-column
        prop="founder"
        label="创建人"
        align="center">
      </el-table-column>
      <el-table-column
        label="资源库类型"
        align="center">
        <template slot-scope="scope">
          <span >
            <el-tag
              v-if="scope.row.roleId==1"
              :type="success"
              disable-transitions>
              班级资源库
            </el-tag>
            <el-tag
            v-if="scope.row.roleId==2"
            :type="success"
            disable-transitions>
              公共资源库
            </el-tag>
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="资源库状态"
        align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status==1"> 正常 </span>
          <span v-if="scope.row.status==2"> 经用 </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="path"
        label="资源库路径"
        align="center">
        <template slot-scope="scope">
          <span > user_space/{{scope.row.id}} </span>
        </template>
      </el-table-column>
      <el-table-column
        label="资源库文件"
        align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="toStoreHouse(scope.row)">查看资源库</el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="dialogFormVisible = true">编辑</el-button>
          <el-button size="mini" type="danger" @click="deleteRow(scope.$index, tableData)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--    对话框-->
    <el-dialog title="修改班级信息" :visible.sync="dialogFormVisible" width="500px">
      <el-form :model="tableData">
        <el-form-item label="班级名称" :label-width="formLabelWidth">
          <el-input v-model="tableData.ClassName" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible = false;modifySubmit">确 定</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {export2Excel} from "../../utils/excel"
import {dataFiltering} from "../../utils";

export default {
  name: "ClassInfo",
  data() {
    return {
      itemId: this.$route.query.teamId,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      tableData: [],
      form: {},
    }
  },
  created() {
    console.log(window.sessionStorage.getItem("user"))
    this.getTableData()
  },
  methods: {

    toStoreHouse(row) {
      this.$router.push({
        path: "/storeHouse",
        query:{
          storeHouseId:row.id,
        }
      })
    },
    getTableData() {
      console.log(this.$route.query.teamId)
      let _this = this
      this.$http.storeHouse.findAll().then(result => {
        _this.tableData = result.data
        _this.tableData = dataFiltering(_this.tableData, "teamId", this.itemId)
      })
    },
    createStoreHouse() {
      let form = {id:this.$route.query.teamId}
      let _this = this
      this.$http.teacher.createStoreHouse(form).then(result=>{
        if (result.code=2000) {
          _this.$message({
            type: "success",
            message: "创建成功!"
          })
          _this.getTableData()
        }
      })
    },
    modifySubmit(modifyForm) {
      const _this = this
      this.$refs[modifyForm].validate((valid) => {
        if (valid) {
          this.$confirm("此操作将永久修改信息, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(async () => {
            await this.$http.userMessage.update(this.modifyForm).then(function (res) {
              if (res.code == 2000) {
                _this.modifySync = false
                _this.$message({
                  type: "success",
                  message: "修改成功!"
                })
              } else {
                _this.$message({
                  type: "error",
                  message: res.msg
                })
              }
            })
            await this.getUserList()
          }).catch(() => {
            this.$message({
              type: "info",
              message: "已取消修改"
            })
          })
        } else {
          alert("error submit!")
          return false
        }
      })
    },
    deleteRow(index, rows) {
      rows.splice(index, 1)
    }
  }
}


</script>

<style scoped>


</style>
